﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.woodsoft.core;
using com.woodsoft.core.Files;
using EQ1.Objects;

namespace EQ1.Elements {
  public class LayoutStrategy:UIClass, IUIElement<LayoutStrategy> {
    public LayoutStrategy ( UIDocument doc , string name ) : base( doc , name ) {
      this.ResizeHorizontal = false;
      this.ResizeVertical = false;
    }
    public LayoutStrategy ( UIDocument doc ) : this( doc , "LayoutStrategy" ) {
    }

    #region IUIElement<LayoutStrategy> Members

    public void Validate ( LayoutStrategy val , string name ) {
      UIClass par = ( UIClass ) this.ParentNode;

      if( val.LocalName != name ) {
        LayoutStrategy el = new LayoutStrategy( ( UIDocument ) val.OwnerDocument , name );
        el.Copy( val );
        val = el;
      }

      if( par.GetElement( name ) != null )
        par.RemoveElement( name );

      par.AppendChild( val );
    }
    public void Copy ( LayoutStrategy val ) {
      base.Copy( val );

      this.ResizeHorizontal = val.ResizeHorizontal;
      this.ResizeVertical = val.ResizeVertical;

      if( this.Padding != null )
        this.Padding = val.Padding;
    }

    #endregion

    public int? Padding {
      get {
        return int.Parse( this.GetElement( "Padding" ).InnerText );
      }
      set {
        this.Validate( "Padding" , value.ToString() );
      }
    }
    public bool ResizeHorizontal {
      get {
        return bool.Parse( this.GetElement( "ResizeHorizontal" ).InnerText );
      }
      set {
        this.Validate( "ResizeHorizontal" , value.ToString() );
      }

    }
    public bool ResizeVertical {
      get {
        return bool.Parse( this.GetElement( "ResizeVertical" ).InnerText );
      }
      set {
        this.Validate( "ResizeVertical" , value.ToString() );
      }
    }
  }
}
